package GUI;

import Attributes.NANAttribute;
import Attributes.Person;
import Database.DBLoader;
import TableModels.CellRendererExt;
import TableModels.CellRendererRes;
import TableModels.PersonaExtTableModel;
import TableModels.PersonaResTableModel;
import java.awt.CardLayout;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class MainWindow extends javax.swing.JFrame implements ListSelectionListener {

    private PersonaExtTableModel tableModelPersonaExt;
    
    private PersonaResTableModel tableModelPersonaRes;
    
    private ArrayList<Person> personas;
    
    private DBLoader dbLoader;
    
    // Datos de conexion
    private String userName;
    private String password;
    private String ip;
    private String port;
    private String db;    
    private PreferenceFrame pref;

    public MainWindow() {
        myInitComponents();
        initComponents();
        setLocationRelativeTo(null);
        tResumida.getSelectionModel().addListSelectionListener(this);
    }

    public void setConnectionData(String user, String pw, String ip, String port, String db) {
        this.userName = user;
        this.password = pw;
        this.ip = ip;
        this.port = port;
        this.db = db;
    }

    private void myInitComponents() {
        tableModelPersonaExt = new PersonaExtTableModel();
        tableModelPersonaRes = new PersonaResTableModel();
        pref = new PreferenceFrame(this);
        pref.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pMainPanel = new javax.swing.JPanel();
        pResumida = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        taComentario = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        tResumida = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        bSubirResumido = new javax.swing.JButton();
        bBajarResumido = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JSeparator();
        lMensaje = new javax.swing.JLabel();
        pExtendida = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tExtendida = new javax.swing.JTable();
        bSubirExtendido = new javax.swing.JButton();
        bBajarExtendido = new javax.swing.JButton();
        mbMenu = new javax.swing.JMenuBar();
        mArchivo = new javax.swing.JMenu();
        miConectar = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        exportarMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        miSalir = new javax.swing.JMenuItem();
        mVistas = new javax.swing.JMenu();
        miResumida = new javax.swing.JMenuItem();
        miExtendida = new javax.swing.JMenuItem();
        mOpciones = new javax.swing.JMenu();
        miPreferencias = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema de Recomendacion de Becarios CEFCE");

        pMainPanel.setLayout(new java.awt.CardLayout());

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        taComentario.setColumns(20);
        taComentario.setEditable(false);
        taComentario.setRows(5);
        taComentario.setWrapStyleWord(true);
        taComentario.setMaximumSize(new java.awt.Dimension(4, 22));
        jScrollPane2.setViewportView(taComentario);
        taComentario.setLineWrap(true);

        tResumida.setModel(tableModelPersonaRes);
        tResumida.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(tResumida);

        jLabel1.setText("Comentarios:");

        bSubirResumido.setText("Subir");
        bSubirResumido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSubirResumidoActionPerformed(evt);
            }
        });

        bBajarResumido.setText("Bajar");
        bBajarResumido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBajarResumidoActionPerformed(evt);
            }
        });

        lMensaje.setText(" ");

        javax.swing.GroupLayout pResumidaLayout = new javax.swing.GroupLayout(pResumida);
        pResumida.setLayout(pResumidaLayout);
        pResumidaLayout.setHorizontalGroup(
            pResumidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pResumidaLayout.createSequentialGroup()
                .addGroup(pResumidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pResumidaLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pResumidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(bSubirResumido, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bBajarResumido, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)))
                    .addComponent(lMensaje))
                .addContainerGap())
            .addComponent(jSeparator4, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        pResumidaLayout.setVerticalGroup(
            pResumidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pResumidaLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(pResumidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pResumidaLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bSubirResumido)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bBajarResumido)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(lMensaje))
        );

        pMainPanel.add(pResumida, "pResumida");

        tExtendida.setModel(tableModelPersonaExt);
        tExtendida.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane3.setViewportView(tExtendida);

        bSubirExtendido.setText("Subir");
        bSubirExtendido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSubirExtendidoActionPerformed(evt);
            }
        });

        bBajarExtendido.setText("Bajar");
        bBajarExtendido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBajarExtendidoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pExtendidaLayout = new javax.swing.GroupLayout(pExtendida);
        pExtendida.setLayout(pExtendidaLayout);
        pExtendidaLayout.setHorizontalGroup(
            pExtendidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pExtendidaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pExtendidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bSubirExtendido, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bBajarExtendido, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        pExtendidaLayout.setVerticalGroup(
            pExtendidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pExtendidaLayout.createSequentialGroup()
                .addGroup(pExtendidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pExtendidaLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE))
                    .addGroup(pExtendidaLayout.createSequentialGroup()
                        .addGap(112, 112, 112)
                        .addComponent(bSubirExtendido)
                        .addGap(18, 18, 18)
                        .addComponent(bBajarExtendido)
                        .addGap(0, 268, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pMainPanel.add(pExtendida, "pExtendida");

        mArchivo.setText("Archivo");

        miConectar.setText("Conectar");
        miConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miConectarActionPerformed(evt);
            }
        });
        mArchivo.add(miConectar);
        mArchivo.add(jSeparator1);

        exportarMenu.setText("Exportar...");
        exportarMenu.setEnabled(false);

        jMenuItem1.setText(".txt");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        exportarMenu.add(jMenuItem1);

        mArchivo.add(exportarMenu);
        mArchivo.add(jSeparator3);

        miSalir.setText("Salir");
        miSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSalirActionPerformed(evt);
            }
        });
        mArchivo.add(miSalir);

        mbMenu.add(mArchivo);

        mVistas.setText("Vistas");

        miResumida.setText("Resumida");
        miResumida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miResumidaActionPerformed(evt);
            }
        });
        mVistas.add(miResumida);

        miExtendida.setText("Extendida");
        miExtendida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miExtendidaActionPerformed(evt);
            }
        });
        mVistas.add(miExtendida);

        mbMenu.add(mVistas);

        mOpciones.setText("Opciones");

        miPreferencias.setText("Preferencias");
        miPreferencias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miPreferenciasActionPerformed(evt);
            }
        });
        mOpciones.add(miPreferencias);

        mbMenu.add(mOpciones);

        setJMenuBar(mbMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pMainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pMainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miExtendidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExtendidaActionPerformed
        CardLayout layout = (CardLayout) pMainPanel.getLayout();
        layout.show(pMainPanel, "pExtendida");
    }//GEN-LAST:event_miExtendidaActionPerformed

    private void miResumidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miResumidaActionPerformed
        CardLayout layout = (CardLayout) pMainPanel.getLayout();
        layout.show(pMainPanel, "pResumida");
    }//GEN-LAST:event_miResumidaActionPerformed

    private void bSubirResumidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSubirResumidoActionPerformed
        int selectedRow = tResumida.getSelectedRow();
        if (selectedRow > 0) {
            Person toMove = personas.get(selectedRow);
            personas.remove(toMove);
            personas.add(selectedRow - 1, toMove);
            ListSelectionModel selectionModel = tResumida.getSelectionModel();
            selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            selectionModel.setSelectionInterval(0, selectedRow - 1);
            tResumida.repaint();
            tExtendida.repaint();
        }
    }//GEN-LAST:event_bSubirResumidoActionPerformed

    private void bBajarResumidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBajarResumidoActionPerformed
        int selectedRow = tResumida.getSelectedRow();
        if ((selectedRow != -1) && (selectedRow < personas.size() - 1)) {
            Person toMove = personas.get(selectedRow);
            personas.remove(toMove);
            personas.add(selectedRow + 1, toMove);
            ListSelectionModel selectionModel = tResumida.getSelectionModel();
            selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            selectionModel.setSelectionInterval(0, selectedRow + 1);
            tResumida.repaint();
            tExtendida.repaint();
        }
    }//GEN-LAST:event_bBajarResumidoActionPerformed

    private void bSubirExtendidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSubirExtendidoActionPerformed
        int selectedRow = tExtendida.getSelectedRow();
        if (selectedRow > 0) {
            Person toMove = personas.get(selectedRow);
            personas.remove(toMove);
            personas.add(selectedRow - 1, toMove);
            ListSelectionModel selectionModel = tExtendida.getSelectionModel();
            selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            selectionModel.setSelectionInterval(0, selectedRow - 1);
            tResumida.repaint();
            tExtendida.repaint();
        }
    }//GEN-LAST:event_bSubirExtendidoActionPerformed

    private void bBajarExtendidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBajarExtendidoActionPerformed
        int selectedRow = tExtendida.getSelectedRow();
        if ((selectedRow != -1) && (selectedRow < personas.size() - 1)) {
            Person toMove = personas.get(selectedRow);
            personas.remove(toMove);
            personas.add(selectedRow + 1, toMove);
            ListSelectionModel selectionModel = tExtendida.getSelectionModel();
            selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            selectionModel.setSelectionInterval(0, selectedRow + 1);
            tResumida.repaint();
            tExtendida.repaint();
        }
    }//GEN-LAST:event_bBajarExtendidoActionPerformed

    private void miPreferenciasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miPreferenciasActionPerformed
        pref.setVisible(true);
    }//GEN-LAST:event_miPreferenciasActionPerformed

    private void miConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miConectarActionPerformed
        conectar();
    }//GEN-LAST:event_miConectarActionPerformed

    public void conectar(){
        dbLoader = new DBLoader("//" + ip + ":" + port + "/" + db, userName, password);
        try {
            dbLoader.load();
            cargarGUI();
            exportarMenu.setEnabled(true);
            pref.enableGuardar();
            lMensaje.setText("Base de datos conectada con exito!");
        } catch (SQLException ex) {
            lMensaje.setText("Error al tratar de conectar con la BD. Compruebe que los datos ingresados sean correctos.");
        }
    }
    
    private void miSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSalirActionPerformed
        
    }//GEN-LAST:event_miSalirActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        try {
            JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir") + "\\Output");
            int returnVal = fileChooser.showSaveDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                javax.swing.JTable tableShowing;
                if (tResumida.isShowing()) {
                    tableShowing = tResumida;
                } else {
                    tableShowing = tExtendida;
                }
                FileWriter fstream = new FileWriter(fileChooser.getSelectedFile().getAbsolutePath());
                BufferedWriter out = new BufferedWriter(fstream);
                for (int y = 0; y < tableShowing.getColumnCount(); y++) {
                    out.append(tableShowing.getColumnName(y) + ',');
                }
                out.append(System.getProperty("line.separator"));
                for (int i = 0; i < tableShowing.getRowCount(); i++) {
                    for (int j = 0; j < tableShowing.getColumnCount(); j++) {
                        String value = String.valueOf(tableShowing.getValueAt(i, j));
                        out.append(value + ',');
                    }
                    out.append(System.getProperty("line.separator"));

                }
                out.close();
                lMensaje.setText("Archivo " + fileChooser.getSelectedFile().getName() + " guardado con exito!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBajarExtendido;
    private javax.swing.JButton bBajarResumido;
    private javax.swing.JButton bSubirExtendido;
    private javax.swing.JButton bSubirResumido;
    private javax.swing.JMenu exportarMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JLabel lMensaje;
    private javax.swing.JMenu mArchivo;
    private javax.swing.JMenu mOpciones;
    private javax.swing.JMenu mVistas;
    private javax.swing.JMenuBar mbMenu;
    private javax.swing.JMenuItem miConectar;
    private javax.swing.JMenuItem miExtendida;
    private javax.swing.JMenuItem miPreferencias;
    private javax.swing.JMenuItem miResumida;
    private javax.swing.JMenuItem miSalir;
    private javax.swing.JPanel pExtendida;
    private javax.swing.JPanel pMainPanel;
    private javax.swing.JPanel pResumida;
    private javax.swing.JTable tExtendida;
    private javax.swing.JTable tResumida;
    private javax.swing.JTextArea taComentario;
    // End of variables declaration//GEN-END:variables

    public void valueChanged(ListSelectionEvent e) {
        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
        if (!lsm.isSelectionEmpty() && (!e.getValueIsAdjusting())) {
            try {
                int index = lsm.getMaxSelectionIndex();
                int lu = Integer.parseInt(((NANAttribute) tResumida.getValueAt(index, 0)).toString());
                ResultSet result = dbLoader.executeQuery("SELECT * FROM APP.COMENTARIO WHERE LU='" + lu + "'");
                if (result.next()) {
                    taComentario.setText(result.getString("COMENTARIO"));
                } else {
                    taComentario.setText("Sin Comentarios");
                }
            } catch (SQLException ex) {
                setMessage(ex.getMessage());
            }
        }
    }
    
    public void setMessage(String message) {
        new Exception().printStackTrace();
        lMensaje.setText(message);
    }
    
    public void cargarGUI() {
        personas = dbLoader.getPersons();
        myInitComponents();
        tableModelPersonaExt.load(personas);
        tExtendida.setModel(tableModelPersonaExt);
        CellRendererExt rendererExt = new CellRendererExt(dbLoader, 8);
        for (int i = 0; i < tExtendida.getColumnCount(); i++) {
            tExtendida.getColumnModel().getColumn(i).setCellRenderer(rendererExt);
        }
        tableModelPersonaRes.load(personas);
        tableModelPersonaRes.addTableModelListener(tResumida);
        tResumida.setModel(tableModelPersonaRes);
        CellRendererRes rendererRes = new CellRendererRes(dbLoader, 0);
        for (int i = 0; i < tResumida.getColumnCount(); i++) {
            tResumida.getColumnModel().getColumn(i).setCellRenderer(rendererRes);
        }
        try {
            pref.updateTable(dbLoader);
        } catch (SQLException ex) {
            setMessage(ex.getMessage());
        }
    }
}
